package tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
	public static void main(String[] args) throws Exception {
		
		ServerSocket server = new ServerSocket(8888);
		/**open port**/
		/**block current thread**/
		
		while(true){
			Socket socket = server.accept();
			System.out.println("continue...");
			
			OutputStream out = socket.getOutputStream();
			InputStream in = socket.getInputStream();
			out.write("Who are u? \n".getBytes());
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(in));
			String name = reader.readLine();
			out.write(("Hello"+name+"\n").getBytes());
			
			out.close();
			reader.close();
			in.close();
			socket.close();
		}
		
//		server.close();
		
		
	}

}
